package com.winit.common.CloudLinkSend;

import com.winit.commons.util.ObjectToString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;


/**
 * Created by wanglin on 2018/4/8.
 */
@Component
public class MsgSend {
    private static Logger logger = LoggerFactory.getLogger(MsgSend.class);
    @Autowired
    private AmqpTemplate rabbitTemplate;

    @Value("${matrix_online_exchange}")
    private String matrix_online_exchange;

    @Value("${plan_send_exchange}")
    private String plan_send_exchange;

    @Value("${req_send_exchange}")
    private String req_send_exchange;

    @Value("${issue_send_exchange}")
    private String issue_send_exchange;

//    消息发送对应关系 plan -> req -> issue -> need

    public void sendMsg(MqMsgType type, Map map) {
        MqMessage message = new MqMessage();
        message.setMap(map);
        message.setType(type);
        sendMsg(matrix_online_exchange, message);
    }

    public void sendPlanMsg(MqMsgType type,Map map){
        MqMessage message = new MqMessage();
        message.setMap(map);
        message.setType(type);
        this.rabbitTemplate.convertAndSend(plan_send_exchange, "#-status-queue", message);
    }

    public void sendReqMsg(MqMsgType type,Map map){
        MqMessage message = new MqMessage();
        message.setMap(map);
        message.setType(type);
        this.rabbitTemplate.convertAndSend(req_send_exchange, "#-status-queue", message);
    }
    public void sendIssueMsg(MqMsgType type,Map map){
        MqMessage message = new MqMessage();
        message.setMap(map);
        message.setType(type);
        this.rabbitTemplate.convertAndSend(issue_send_exchange, "#-status-queue", message);
    }

    public void sendMsg(String exchange, MqMessage message) {
        logger.info("com.winit.common.CloudLinkSend.MsgSend.sendMsg map=" + ObjectToString.getString(message));
        this.rabbitTemplate.convertAndSend(exchange, "no-use", message);
    }
}
